from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from common import CSVreader
import os
caps=CSVreader.csvreader_dict(os.path.dirname(os.path.dirname(__file__))+'\config\config.csv')
url='http://127.0.0.1:4723/wd/hub'
dr=webdriver.Remote(url,caps)
dr.implicitly_wait(15)
def Click_xpath(Xpath):
    dr.find_element(AppiumBy.XPATH,Xpath).click()
def reset():
    dr.reset()
def input_xpath(Xpath,value):
    dr.find_element(AppiumBy.XPATH,Xpath).send_keys(value)
def locater_Xpath(Xpath):
    return dr.find_element(AppiumBy.XPATH,Xpath)
def click_ID(ID):
    dr.find_element(AppiumBy.ID,ID).click()
def locater_list_class(class_name):
    return dr.find_elements(AppiumBy.CLASS_NAME,class_name)
def locater_class(class_name):
    return dr.find_element(AppiumBy.CLASS_NAME,class_name)
def click_class(class_name):
    dr.find_element(AppiumBy.CLASS_NAME,class_name).click()
def input_class(class_name,value):
    dr.find_element(AppiumBy.CLASS_NAME,class_name).send_keys(value)
def click_accID(accID):
    dr.find_element(AppiumBy.ACCESSIBILITY_ID,accID).click()
def start_activity(package,activity):
    dr.start_activity(package,activity)
def perent_input_ID_xpath(perent,child,add):
    perent_element=dr.find_element(AppiumBy.ACCESSIBILITY_ID,perent)
    child=perent_element.find_element(AppiumBy.XPATH,child)
    child.click()
    child.send_keys(add)
def perent_click_xpath_class(perent,child):
    perent=dr.find_element(AppiumBy.XPATH,perent)
    child=perent.find_elements(AppiumBy.CLASS_NAME,child)
    return child